package Algorithm.Othes;

import java.util.ArrayList;
import java.util.List;

// https://leetcode-cn.com/problems/number-of-lines-to-write-string/
public class Leetcode806_写字符串需要的行数 {
    class Solution {
        public int[] numberOfLines(int[] widths, String s) {
            List<Integer> results = new ArrayList<Integer>();
            int lineWidth = 100;
            int nums = 1;
            for(int i = 0; i < s.length(); i++){
                if (lineWidth >= widths[(int)(s.charAt(i) - 'a')]){
                    lineWidth = lineWidth - widths[(int)(s.charAt(i) - 'a')];
                }else{
                    nums++;
                    lineWidth = 100;
                    lineWidth = lineWidth - widths[(int)(s.charAt(i) - 'a')];
                }
            }

            return new int[]{nums, 100-lineWidth};
        }
    }
}
